﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;

using MaxStudio.Concrete.DBUtility;

namespace MaxStudio.Concrete.Server.Dao
{
    public partial class ConcreteDaoDataContext : System.Data.Linq.DataContext
    {
        #region RTPCementStrength

        public List<tb_RPT_CementStrength> GetAllCementStrength()
        {
            var query = (from obj in this.tb_RPT_CementStrengths
                         where obj.IsDelete == 0
                         select obj).ToList();
            return query;
        }


        public List<tb_RPT_CementStrength> GetCementStrengthByContition(string strTestDate, string strCementManufacturer
                                                                    ,string strCementLabel, string strAshManufacturer, string strQuickSide
                                                                    , string str3DStrength, string str7DStrength, string str7DIndex
                                                                    , string str28DStrength, string str28DIndex, string strStatistician)
 
        {
            var tq = from obj in this.tb_RPT_CementStrengths
                     where obj.IsDelete == 0
                     select obj;

            if (strTestDate.Length > 0)
            {
                tq = tq.Where(entity => entity.TestDate == strTestDate);
            }

            if (strCementManufacturer.Length > 0)
            {
                tq = tq.Where(entity => entity.CementManufacturer == strCementManufacturer);
            }

            if (strCementLabel.Length > 0)
            {
                tq = tq.Where(entity => entity.CementLabel == strCementLabel);
            }

            if (strAshManufacturer.Length > 0)
            {
                tq = tq.Where(entity => entity.AshManufacturer == strAshManufacturer);
            }
            if (strQuickSide.Length > 0)
            {
                tq = tq.Where(entity => entity.QuickSide == strQuickSide);
            }

            if (str3DStrength.Length > 0)
            {
                tq = tq.Where(entity => entity._3DStrength == str3DStrength);
            }

            if (str7DStrength.Length > 0)
            {
                tq = tq.Where(entity => entity._7DStrength == str7DStrength);
            }
            if (str7DIndex.Length > 0)
            {
                tq = tq.Where(entity => entity._7DIndex == str7DIndex);
            }
            if (str28DStrength.Length > 0)
            {
                tq = tq.Where(entity => entity._28DStrength == str28DStrength);
            }
            if (strStatistician.Length > 0)
            {
                tq = tq.Where(entity => entity.Statistician == strStatistician);
            }
             

            var query = tq.ToList();
            return query;
        }

        public tb_RPT_CementStrength GetCementStrengthById(int id)
        {
            return this.tb_RPT_CementStrengths.SingleOrDefault(tb_RPT_CementStrengths => tb_RPT_CementStrengths.Id == id);
        }

        public void CreateCementStrength(tb_RPT_CementStrength entity)
        {
            entity.CreateDate = DateTime.Now;
            entity.CreateBy = 1;
            entity.ModifyDate = DateTime.Now;
            entity.ModifyBy = 1;
            tb_RPT_CementStrengths.InsertOnSubmit(entity);
            this.SubmitChanges();

        }

        public void ModifyCementStrength(tb_RPT_CementStrength entity)
        {
            tb_RPT_CementStrength instance = this.tb_RPT_CementStrengths.SingleOrDefault(p => p.Id == entity.Id);
            instance.TestDate = entity.TestDate;
            instance.CementManufacturer = entity.CementManufacturer;
            instance.CementLabel = entity.CementLabel;
            instance.AshManufacturer = entity.AshManufacturer;
            instance.QuickSide = entity.QuickSide;
            instance._3DStrength = entity._3DStrength;
            instance._7DStrength = entity._7DStrength;
            instance._7DIndex = entity._7DIndex;
            instance._28DStrength = entity._28DStrength;
            instance._28DIndex = entity._28DIndex;
            instance.Statistician = entity.Statistician; 

            instance.IsDelete = entity.IsDelete;
            instance.ModifyBy = 1; //Need to get current user
            instance.ModifyDate = DateTime.Now;

            this.SubmitChanges();
        }

        public void DeleteCementStrength(tb_RPT_CementStrength entity)
        {
            tb_RPT_CementStrength deleteEntity = tb_RPT_CementStrengths.SingleOrDefault(p => p.Id == entity.Id);
            tb_RPT_CementStrengths.DeleteOnSubmit(deleteEntity);

            this.SubmitChanges();
        }

        #endregion

    }

}
